package cn.lzit.sy4;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class OrderServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        String[] foodName = request.getParameterValues("choice");
        HttpSession session = request.getSession();

        if (foodName != null) {
            for (int k = 0; k < foodName.length; k++) {
                session.setAttribute(foodName[k], foodName[k]);
            }
        }

        String url = "<a href='/chapter05/cart'>欢迎去购物车页面！</a>";
        response.getWriter().println("<p>点击超链接，链接到购物车页面,去查看购物车中的商品。<br />" + url + "</p>");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}